/*
 * This file is part of SSHTTPD.
 *
 * SSHTTPD is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * SSHTTPD is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _UTILS_H
#define _UTILS_H

/** @file 
 * Defines global structures and functions implemented and used by utils.c
 */

#include <unistd.h>

#define EVENTOUT stdout

/**
 * Used for safe printing of strings, if not null returns the string
 * else "null" is returned.
 */
#define SAFEPSTR(x) (x != NULL) ? x : "null"

/** Standard logging level. */
#define ELOG 0 
/** Warning log level. */
#define EWARN 1 
/** Error log level. */
#define EPROB 2 
/** Console log level. */
#define ECON 3  

/**
 * Provides leveled logging with a printf style argument system.
 * @param type Type of evet to be logged, ELOG, EWARN etc..
 * @param format Printf style format.
 * @param ... Variable args depending on format.
 */
void event(int type, char *format, ...);

/**
 * Allocates a string onto the heap.
 * @param str String to copy.
 * @return String pointer if success, NULL on fail. Needs to be free()'d.
 */
char *heapstr(char *str);
#endif
